#define _CRT_SECURE_NO_WARNINGS 1
#include"stack.h"
void Add_capacity(ST* stack)
{
	ST* ret = (Mt*)realloc(stack->ptr,sizeof(Mt) * 2 * stack->capacity);
	if (!ret)
	{
		perror("realloc:");
	}
	else
	{
		stack->ptr = ret;
	}
}
void judge(ST* stack)
{
	if (stack->top == stack->capacity)
	{
		Add_capacity(stack);
	}
}
void STinit(ST* stack)
{
	assert(stack);
	stack->top = 0;
	stack->ptr = (Mt*)malloc(sizeof(Mt) * 4);
	stack->capacity = 4;
	memset(stack->ptr, 0, sizeof stack->ptr);
}
void STpush(ST* stack, Mt x)
{
	assert(stack);
	judge(stack);
	stack->ptr[stack->top] = x;
	stack->top++;
}
void STpop(ST* stack)
{
	assert(stack);
	if (stack->top == 0)
	{
		return;
	}
	stack->top--;
}
int STtop(ST* stack)
{
	return stack->ptr[stack->top - 1];
}
bool STempty(ST* stack)
{
	return stack->top == 0;
}
void STprint(ST* stack)
{
	assert(stack);
	while (!STempty(stack))
	{
		printf("%d", STtop(stack));
		STpop(stack);
	}
	printf("\n");
}